package com.vancouver.knows.ui.activity.login;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;

import com.vancouver.knows.R;
import com.vancouver.knows.ui.base.BaseActivity;

public class ChooseCountryActivity extends BaseActivity {

	private Context mContext;
	@Bind(R.id.common_tips)
	TextView  mCommonTips;
	@Bind(R.id.common_back)
	ImageView mCommonBack;
	@Bind(R.id.list_country)
	RelativeLayout mCountryList;
	@Bind(R.id.try_email_register)
	TextView mTryEmailRegister;
	private String mCurrentActivity;
	
	private ChooseCountryView mChooseCountryView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login_choose_country);
		mContext = ChooseCountryActivity.this;
		setViews();
		setListeners();
	}

	private void setViews() {
		Intent intent = getIntent();
		String tips = intent.getStringExtra("COMMON_TIPS");
		mCurrentActivity = intent.getStringExtra("CURRENT_OPEN_ACTIVITY");
		mCommonTips.setText(tips);
		
		mChooseCountryView = new ChooseCountryView(mContext, mHandler, mCurrentActivity);
		mCountryList.addView(mChooseCountryView);
		
	}
	
	private void setListeners(){
		mCommonBack.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
	
	@OnClick(R.id.try_email_register)
	public void OnTryEmailRegisterClick(){
		Intent intent = new Intent(mContext, EmailSecurityCodeActivity.class);
		intent.putExtra("COMMON_TIPS", mContext.getString(R.string.email_register).toString());
		mContext.startActivity(intent);
	}

	@SuppressLint("HandlerLeak")
	private Handler mHandler = new Handler(){	
		public void handleMessage(android.os.Message msg) {
			finish();
		};
	};
}